<script>
import dmbTable from "@/components/LTable/index.vue";
import {
  tableBase,
  cellStyle,
  headerCellStyle,
  tableFormStyle,
  formItemStyle,
} from "./config";
import { self_pickup_point_delAPI } from "@/api/data/extra-long-fee.js";

import dayjs from "dayjs";

export default {
  name: "self_pickup_point",
  computed: {
    formItemStyle() {
      return formItemStyle;
    },
    tableFormStyle() {
      return tableFormStyle;
    },
    cellStyle() {
      return cellStyle;
    },
    headerCellStyle() {
      return headerCellStyle;
    },
  },
  components: { dmbTable },
  data() {
    return {
      requestConfig: {
        url: "/base/selfPickupPoint/list",
        method: "get",
        montage: true,
      },
      saveRequest: {
        url: "/base/selfPickupPoint/save",
        method: "post",
        montage: false,
      },
      selectionArr: [], // 多选框内容
    };
  },

  methods: {
    tableBase() {
      return tableBase;
    },
    // 多选框内容
    selectionChange(data) {
      this.selectionArr = data;
    },
    // 导出
    async downLoad() {
      if (this.selectionArr.length > 0) {
        const ids = this.selectionArr.map((v) => v.id);
        this.download(
          "/base/selfPickupPoint/export",
          {
            ids,
          },
          `自提点_${dayjs().format("YYYY/MM/DD hh:mm:ss")}.xlsx`
        );
      } else {
        this.$message.error("请选择条数据导出");
      }
    },
    async del(id) {
      await this.$confirm("确定要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      });
      await self_pickup_point_delAPI(id);
      this.$refs.table.getListData();
      this.$message.success("删除成功");
    },
  },
};
</script>

<template>
  <div>
    <template class="flex flex-row-reverse">
      <div class="mb-3 flex flex-row-reverse">
        <div>
          <el-button type="success" @click="$refs.table.getListData()"
            >查询</el-button
          >
          <el-button type="success" @click="$refs.table.saveToUpdate()"
            >保存</el-button
          >
          <el-button type="primary" @click="downLoad">导出</el-button>
        </div>
      </div>
    </template>

    <div>
      <dmb-table
        ref="table"
        :prop-list="tableBase()"
        :operateWether="true"
        :is-operate="true"
        :show-index-column="true"
        select-column-type="CHECKBOX"
        :req-request="requestConfig"
        :isSaveToUpadate="true"
        :saveRequest="saveRequest"
        select-key="id"
        :cell-style="cellStyle"
        :header-cell-style="headerCellStyle"
        :initialize="false"
        :change-search-form="false"
        :show-footer="true"
        :form-item-style="tableFormStyle"
        @selectionChange="
          (row) => {
            selectionArr = row;
          }
        "
      >
        <template v-slot:operate="{ row }">
          <el-button type="danger" v-if="row.id" @click="del(row.id)"
            >删除</el-button
          >
        </template>
        <!-- 是否到付 -->
        <template v-slot:isToPay="{ row }">
          <el-checkbox v-model="row.isToPay" :true-label="1" :false-label="0">
          </el-checkbox>
        </template>
        <!-- 寄件 -->
        <template v-slot:sending="{ row }">
          <el-checkbox v-model="row.sending" :true-label="1" :false-label="0">
          </el-checkbox>
        </template>
        <!-- 是否启用 -->
        <template v-slot:是否启用="{ row }">
          <el-checkbox v-model="row.是否启用" :true-label="1" :false-label="0">
          </el-checkbox>
        </template>
      </dmb-table>
    </div>
  </div>
</template>

<style scoped lang="scss">
</style>
